import torch

t1 = torch.rand(8, 5)
e = torch.rand(8, 5) * 1e-8

t2 = t1 + e

# 比较两个tensor是否在指定误差范围内相等
print(torch.allclose(t1, t2, 0.001, 0.001))  # True

t3 = t1.clone()

# 比较两个tensor是否二进制相等，逐元素比较，返回tensor
print(torch.eq(t1, t3))
# tensor([[True, True, True, True, True],
#         [True, True, True, True, True],
#         [True, True, True, True, True],
#         [True, True, True, True, True],
#         [True, True, True, True, True],
#         [True, True, True, True, True],
#         [True, True, True, True, True],
#         [True, True, True, True, True]])


# 比较两个tensor是否二进制相等，也是逐元素比较，返回True/False
print(torch.equal(t1, t3))  # True